//手机号校验
export const isMobile = (str) => {
	if(str == null || str == "") return false;
	let result = str.match(/^1(3|4|5|7|8|9)\d{9}$/);
	if(result == null) return false;
	return true;
};
//非空校验
export const isRequired = (str) => {
	if(str == null || str == "") return false;
	return true;
};

/*//6-20位数字和字母密码验证
export const isPassWord = (str) => {
	if(str == null || str == "") return false;
	let result = str.match(/^(?!([a-zA-Z]+|\d+)$)[a-zA-Z\d]{6,20}$/);
	if(result == null) return false;
	return true;
};*/
//密码校验
export const isPassWord = (str) => {
	if(str == null || str == "") return false;
	if(str.length < 6 || str.length > 20) return false;
	return true;
};

//校验是否为两位小数
export const isNum = (str) => {
	if(str == null || str == "") return false;
	let result = str.match(/^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/);
	if(result == null) return false;
	return true;
};

export const isCardNo = (card) => {
	// 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
	var reg =
		/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
	if(reg.test(card)) {
		return true;
	}
};

//正整数(非0)
export const isPositiveNum = (val) => {
	var reg = /^[1-9]\d*$/;
	return reg.test(val);
};

//正整数(含0)
export const isPositiveNum0 = (val) => {
	var reg = /^[0-9]\d*$/;
	return reg.test(val);
};

//缅甸国家手机号格式校验
let rulesArr = sessionStorage.getItem('mobileRules') ? JSON.parse(sessionStorage.getItem('mobileRules')) : null; //rulesArr = [{"name":"ChinaMobile","rules":[{"prefix":"150","length":11},{"prefix":"159","length":11}]},{"name":"TEST中国联通","rules":[{"prefix":"137","length":11},{"prefix":"130","length":11}]},{"name":"新增运营商TEST","rules":[{"prefix":"159","length":11}]},{"name":"CDMA","rules":[{"prefix":"0991","length":10},{"prefix":"0973","length":10},{"prefix":"0949","length":10},{"prefix":"0947","length":10},{"prefix":"0987","length":9},{"prefix":"0986","length":9},{"prefix":"0985","length":9},{"prefix":"0983","length":9},{"prefix":"0968","length":9},{"prefix":"0965","length":9},{"prefix":"0964","length":9},{"prefix":"0963","length":9}]},{"name":"Mectel","rules":[{"prefix":"0936","length":10},{"prefix":"0934","length":11},{"prefix":"0933","length":10},{"prefix":"0932","length":10},{"prefix":"0931","length":10},{"prefix":"0930","length":10}]},{"name":"Mytel","rules":[{"prefix":"0969","length":11},{"prefix":"0968","length":11},{"prefix":"0967","length":11},{"prefix":"0966","length":11}]},{"name":"Telenor","rules":[{"prefix":"0979","length":11},{"prefix":"0978","length":11},{"prefix":"0977","length":11},{"prefix":"0976","length":11},{"prefix":"0975","length":11}]},{"name":"Ooredoo","rules":[{"prefix":"0997","length":11},{"prefix":"0995","length":11},{"prefix":"0996","length":11}]},{"name":"MPT","rules":[{"prefix":"0989","length":11},{"prefix":"0945","length":11},{"prefix":"0944","length":11},{"prefix":"0943","length":11},{"prefix":"0942","length":11},{"prefix":"0941","length":11},{"prefix":"0940","length":11},{"prefix":"0926","length":11},{"prefix":"0925","length":11},{"prefix":"0943","length":10},{"prefix":"0941","length":10},{"prefix":"0924","length":9},{"prefix":"0923","length":9},{"prefix":"0922","length":9},{"prefix":"0921","length":9},{"prefix":"0920","length":9},{"prefix":"0956","length":9},{"prefix":"0955","length":9},{"prefix":"0954","length":9},{"prefix":"0953","length":9},{"prefix":"0952","length":9},{"prefix":"0951","length":9},{"prefix":"0950","length":9}]}];
if(!rulesArr) rulesArr = [{"name":"ChinaMobile","rules":[{"prefix":"150","length":11},{"prefix":"159","length":11}]},{"name":"TEST中国联通","rules":[{"prefix":"137","length":11},{"prefix":"130","length":11}]},{"name":"新增运营商TEST","rules":[{"prefix":"159","length":11}]},{"name":"CDMA","rules":[{"prefix":"0991","length":10},{"prefix":"0973","length":10},{"prefix":"0949","length":10},{"prefix":"0947","length":10},{"prefix":"0987","length":9},{"prefix":"0986","length":9},{"prefix":"0985","length":9},{"prefix":"0983","length":9},{"prefix":"0968","length":9},{"prefix":"0965","length":9},{"prefix":"0964","length":9},{"prefix":"0963","length":9}]},{"name":"Mectel","rules":[{"prefix":"0936","length":10},{"prefix":"0934","length":11},{"prefix":"0933","length":10},{"prefix":"0932","length":10},{"prefix":"0931","length":10},{"prefix":"0930","length":10}]},{"name":"Mytel","rules":[{"prefix":"0969","length":11},{"prefix":"0968","length":11},{"prefix":"0967","length":11},{"prefix":"0966","length":11}]},{"name":"Telenor","rules":[{"prefix":"0979","length":11},{"prefix":"0978","length":11},{"prefix":"0977","length":11},{"prefix":"0976","length":11},{"prefix":"0975","length":11}]},{"name":"Ooredoo","rules":[{"prefix":"0997","length":11},{"prefix":"0995","length":11},{"prefix":"0996","length":11}]},{"name":"MPT","rules":[{"prefix":"0989","length":11},{"prefix":"0945","length":11},{"prefix":"0944","length":11},{"prefix":"0943","length":11},{"prefix":"0942","length":11},{"prefix":"0941","length":11},{"prefix":"0940","length":11},{"prefix":"0926","length":11},{"prefix":"0925","length":11},{"prefix":"0943","length":10},{"prefix":"0941","length":10},{"prefix":"0924","length":9},{"prefix":"0923","length":9},{"prefix":"0922","length":9},{"prefix":"0921","length":9},{"prefix":"0920","length":9},{"prefix":"0956","length":9},{"prefix":"0955","length":9},{"prefix":"0954","length":9},{"prefix":"0953","length":9},{"prefix":"0952","length":9},{"prefix":"0951","length":9},{"prefix":"0950","length":9}]}];
//for(let x of rulesArr) {
//		console.log(x)
//	}
export const BurmaMobileVerify = (val) => {
	let str3 = val.substr(0, 3);
	let str4 = val.substr(0, 4);
	let str5 = val.substr(0, 5);
	let n = 0;
	for(let x of rulesArr) {
		for(let y of x.rules) {
			if(str3 == y.prefix && val.length == y.length) n++;
			if(str4 == y.prefix && val.length == y.length) n++;
			if(str5 == y.prefix && val.length == y.length) n++;
		}
	}
	return n == 0 ? false : true;
}